home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / DRAGRACE.ZIP / DRAGRACE.ASM next >
Assembly Source File  |  1995-07-09  |  6KB  |  374 lines

  1. ; lil' 256byte drag racing game
  2. ;
  3. ; This is a 2 player game where each player hammers away at the shift keys
  4. ;  to race each other to the finish line.
  5. ;
  6. ;
  7. ;Features:
  8. ;  VGA graphics
  9. ;  multi-channel sounds
  10. ;
  11. ;
  12. ; Written by kenbo@donut.dialix.oz.au (Ken Chick)
  13. ;
  14. ;
  15. ;
  16. ; IMPORTANT: move the_player array around to where the offset address's
  17. ;       bit 3 is 0!!!  You can use ALIGN 8 to make sure it is.  This is
  18. ;       because of opcode modifying stuff in the game.
  19. ;
  20. ;
  21. ;* You can toggle the compiling options for different game styles(see below)
  22. ;
  23. ;* I was going to put 2 cars in it with computer player but I ran out of
  24. ;   space. :(
  25. ;
  26.  
  27.  
  28. ;********** Format of the car images at the end ********************
  29. ;
  30. ; 0000 0000
  31. ; ^^^^ ^^^^
  32. ; ││└┤ └┴┴┴──── Length of the line
  33. ; ││ │
  34. ; ││ └───────── Color of dot 0=invisible
  35. ; ││
  36. ; │└─────────── Goes to next line if this bit is on
  37. ; │
  38. ; └──────────── End of sprite
  39. ;
  40.  
  41.  
  42.  
  43. ;*******************
  44. ; Compiling options...
  45. ; fiddle around with these for different games
  46.  
  47. CAR_TYPE equ 1          ; 0=F1 car, 1=drag racing car
  48. USE_BUTTON equ 2        ; 0=keyboard shifts, 1=mouse buttons
  49. PRINT_WON equ 0         ; whether to print the "won" text string
  50. FLICKER equ 1           ; flickering or not
  51. FLUSH_KEY equ 1         ; flush keyboard on exit, turn this off to save space
  52.  
  53.  
  54. CLIPPING equ 0          ; whether to use clipping or not
  55.  
  56. ;*******************
  57.  
  58. HORZ_WIDTH equ 320
  59. VERT_LENGTH equ 200
  60. SCREEN_SIZE equ (HORZ_WIDTH*VERT_LENGTH)
  61.  
  62.  
  63. FINISH_LINE equ 50      ; where the player finishes
  64.  
  65. .386
  66. model small
  67. smallstack
  68.  
  69. KEY_BUFFER equ 1000h    ; buffer to store keypresses
  70. BADDIES_INFO equ 2000h  ; info on baddies
  71.  
  72.  
  73.  
  74.  
  75.  
  76. _CODE segment use16
  77. ORG 100h
  78.  
  79. assume cs:_CODE,ds:_CODE
  80.  
  81.  
  82. ;********************************************************************
  83.  
  84. ; in: si=sprite numbers, es= screen
  85. ; dx= y position, bx=x position
  86. draw_sprite macro
  87.  
  88. ds_next_line:
  89. inc dx
  90. IF CLIPPING
  91. cmp dx,VERT_LENGTH
  92. jge ds_done
  93. ENDIF
  94. imul di,dx,320
  95. add di,bx
  96.  
  97.     ds_loop:
  98.         mov cl,[si]
  99.         mov ah,cl
  100.         mov al,cl
  101.         and al,30h
  102.         shr al,2
  103.         and cx,0fh
  104.         rep stosb
  105.         inc si
  106.         test ah,0c0h
  107.         js ds_done
  108.         jnz ds_next_line
  109.         jmp ds_loop
  110. ds_done:
  111. endm
  112.  
  113.  
  114.  
  115. main proc
  116.  
  117. mov ax,13h      ; set video mode
  118. int 10h
  119.  
  120.  
  121. ; setup
  122.  
  123. ; setup globals
  124.  
  125. IF FLICKER eq 0
  126. mov ax,cs
  127. add ax,1000h            ; use next segment for video buffer
  128. mov video_buffer,ax
  129. ENDIF
  130. cld
  131.  
  132.  
  133.  
  134.  
  135.  
  136. ; start the sound!
  137. in al,61h
  138. or al,3
  139. out 61h,al
  140.  
  141. main_loop:              ; do game
  142.  
  143. ; clear screen
  144. IF FLICKER
  145. push 0a000h
  146. pop es
  147. mov di,(HORZ_WIDTH*FINISH_LINE)
  148. ELSE
  149. mov es,video_buffer
  150. xor di,di
  151. mov cx,(HORZ_WIDTH*FINISH_LINE)/2
  152. xor ax,ax
  153. rep stosw
  154. ENDIF
  155. mov cx,HORZ_WIDTH
  156. mov al,1
  157. rep stosb
  158. xor ax,ax
  159. mov cx,((SCREEN_SIZE)-((HORZ_WIDTH*FINISH_LINE)+1))/2
  160. rep stosw
  161.  
  162.  
  163. PLAYERS equ 2       ; amount of players
  164.  
  165. ; do sound
  166. mov al,0b6h
  167. out 43h,al      ; pit control
  168. sound_play_offset:
  169. mov cx,word ptr the_players+2
  170. neg cx
  171. add cx,320+40
  172. mov dx,12h
  173. mov ax,34ddh
  174. div cx
  175. out 42h,al
  176. mov al,ah
  177. out 42h,al
  178. xor byte ptr sound_play_offset+2,4
  179.  
  180.  
  181. IF FLICKER
  182. ; wait vga retrace
  183. mov dx,03dah
  184. wait_retrace2: in al,dx
  185. test al,80h
  186. jz wait_retrace2
  187. ENDIF
  188.  
  189. xor bp,bp
  190. mov bx,offset the_players
  191. draw_players:
  192.     push bx
  193.     mov dx,[bx+2]
  194.     cmp dx,FINISH_LINE
  195.     jl game_won
  196.     mov bx,[bx]
  197.     mov si,offset sprite_car
  198.     draw_sprite            ; draw the player
  199.     pop bx
  200.     add bx,4
  201. inc bp
  202. cmp bp,PLAYERS
  203. jl draw_players
  204.  
  205.  
  206.  
  207.  
  208.  
  209. IF FLICKER eq 0
  210. ; wait vga retrace
  211. mov dx,03dah
  212. wait_retrace2: in al,dx
  213. test al,80h
  214. jz wait_retrace2
  215.  
  216. ; copy video buffer to screen
  217. push 0a000h
  218. pop es
  219. mov ds,video_buffer
  220. xor si,si
  221. mov di,si
  222. mov cx,8000h
  223. rep movsw
  224. push cs
  225. pop ds
  226. ENDIF
  227.  
  228.  
  229.  
  230. ; mouse buttons
  231. IF USE_BUTTON eq 1
  232.     mov ax,3
  233.     int 33h
  234.     PLAYER1_BUTTON equ 1
  235.     PLAYER2_BUTTON equ 2
  236. ELSE
  237.     xor ax,ax
  238.     mov fs,ax
  239.     mov bl,byte ptr fs:[417h]
  240.     PLAYER1_BUTTON equ 2
  241.     PLAYER2_BUTTON equ 1
  242. ENDIF
  243. test bl,PLAYER1_BUTTON
  244. last_mouse_info1:
  245. jz not_up1
  246.     xor byte ptr last_mouse_info1,1
  247.     dec word ptr the_players+2
  248. not_up1:
  249. test bl,PLAYER2_BUTTON
  250. last_mouse_info2:
  251. jz not_up2
  252.     xor byte ptr last_mouse_info2,1
  253.     dec word ptr the_players+2+4
  254. not_up2:
  255.  
  256.  
  257. no_mouse_buttons:   ; not mouse buttons changed
  258.  
  259. mov ah,1
  260. int 16h
  261. jz main_loop
  262.  
  263.  
  264. IF FLUSH_KEY
  265. xor ah,ah
  266. int 16h
  267. ENDIF
  268. jmp short quit_game
  269.  
  270.  
  271. game_won:       ; bp=player that won!
  272.  
  273. ; print player won text
  274.  
  275. mov ax,bp
  276. add al,'1'
  277.  
  278. IF PRINT_WON
  279. mov player_won_text,al
  280. mov dx,offset player_won_text
  281. mov ah,9
  282. int 21h
  283. ELSE
  284. mov dl,al
  285. mov ah,2
  286. int 21h
  287. ENDIF
  288.  
  289. quit_game:
  290.  
  291. ; turn the sound off
  292. in al,61h
  293. and al,not 3
  294. out 61h,al
  295.  
  296. mov ax,4c00h    ; get outta here
  297. int 21h
  298. endp
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309. ;********************************************************************
  310. ; data...
  311.  
  312.  
  313.  
  314. IF FLICKER eq 0
  315. video_buffer dw 0       ; segment where 320x200 video buffer is
  316. ENDIF
  317.  
  318.  
  319. ;align 8
  320. the_players:
  321. dw 138,180         ; position of player1
  322. dw 170,180            ; other player
  323.  
  324.  
  325.  
  326. ; sprite for the car
  327. sprite_car:
  328. IF CAR_TYPE eq 1
  329. ; drag racing car
  330. db 2,76h
  331. db 4, 52h
  332. db 2,22h,12h,62h    ; front wheels
  333. db 2,22h,12h,62h    ; front wheels
  334. db 4, 52h
  335. db 4,52h
  336. db 4,52h
  337. db 3,54h
  338. db 3,54h
  339. db 3,54h
  340. db 3,54h
  341. db 23h,14h,63h    ; back wheels
  342. db 23h,14h,63h    ; back wheels
  343. db 23h,14h,63h    ; back wheels
  344. db 4,52h
  345. db 1,0f8h
  346.  
  347. ELSE
  348. ; F1 car
  349. db 1,7ah              ; front bar
  350. db 5h, 52h
  351. db 2,23h,12h,63h    ; front wheels
  352. db 2,23h,12h,63h    ; front wheels
  353. db 4h, 54h
  354. db 1,5ah
  355. db 1,5ah
  356. db 1,5ah
  357. db 1,5ah
  358. db 1,5ah
  359. db 4h,54h
  360. db 24h,14h,64h    ; back wheels
  361. db 24h,14h,64h    ; back wheels
  362. db 24h,14h,64h    ; back wheels
  363. db 4h,54h
  364. db 0fch
  365. ENDIF
  366.  
  367. IF PRINT_WON
  368. player_won_text db '1 won$'
  369. ENDIF
  370.         
  371. ends
  372.  
  373. end main
  374.